package lzupdater;

import java.util.Properties;
import java.util.Map.Entry;

//LZRosterUpdater, a java client to update LZRoster
//Copyright (C) 2008 Fraskor from Krasus (e-mail: fraskor@gmail.com)
//
//This file is part of LZRosterUpdater.
//
//LZRosterUpdater is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Checker that return the java program used to launch it. Only used to find the
 * correct JVM with a specific DOS script file.
 * 
 * @deprecated
 * @author Fraskor
 */
@Deprecated
public class CheckVersion {

	private final boolean valid;

	public CheckVersion(String minVersionAsked) {
		boolean versionOk = false;
		String currentVersion = System.getProperty("java.version");

		String[] currentSplit = currentVersion.split("\\.");
		String[] askedSplit = minVersionAsked.split("\\.");

		int idx = 0;
		while (!versionOk && currentSplit.length > idx
				&& askedSplit.length > idx) {
			int vCurrent = Integer.valueOf(currentSplit[idx]);
			int vAsked = Integer.valueOf(askedSplit[idx]);
			boolean lastDigit = idx == askedSplit.length - 1;

			versionOk = vCurrent > vAsked || (lastDigit && vCurrent == vAsked);
			++idx;
		}
		valid = versionOk;
	}

	public boolean isValid() {
		return valid;
	}

	public String getJavawExe() {
		if (isValid()) {
			String path = System.getenv("prog");
			if (path != null && path.endsWith("java.exe")) {
				return path.substring(0, path.length() - 4) + "w.exe";
			}
		}
		return "";
	}

	public static void main(String[] args) {
		Properties prop = System.getProperties();

		for (Entry<Object, Object> entry : prop.entrySet()) {
			System.err.format("'%s' => '%s'\n", entry.getKey(), entry
					.getValue());
		}

		CheckVersion checker = new CheckVersion("1.5");

		System.out.println(checker.getJavawExe());
	}
}
